import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/app_permission/auth_tab.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/pages/site/site_observer_list/views/my_top_tabbar.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/site_mains_elec_detail/keep_aliver_wrapper.dart';
import 'package:yt_devops/styles/styles.dart';
import 'operation_matainance_controller.dart';

class OperationMatainancePage extends GetView<OperationMatainanceController> {
  const OperationMatainancePage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    // Get.put(OperationMatainanceController());
    Log.d('OperationMatainanceController===');
    return GetBuilder<OperationMatainanceController>(
        init: controller,
        initState: (state) {
          controller.initData();
        },
        builder: (controller) {
          return AuthTab(
            tabList: controller.tabWidgetList,
            build: (context, filtes, tabController) => Scaffold(
              appBar: AppBar(
                title: KeepAliveWrapper(
                  Container(
                    alignment: Alignment.centerLeft,
                    margin: const EdgeInsets.only(bottom: 4),
                    child: SizedBox(
                      width: 160,
                      child: MyTopTabBar(
                        tabController,
                        filtes.map((e) => e.labelString.tr).toList(),
                        labelStyle: TextStyles.f24.mediumStyle,
                        unselectedLabelStyle: TextStyles.styleWith(16.sp,
                            color: Colour.otherTextColor),
                        indicator: const UnderlineTabIndicator(
                          borderSide: BorderSide(
                              width: 0, // 设置边界宽度为0，使其不可见
                              color: Colors.transparent),
                        ),
                      ),
                    ),
                  ),
                ),
                actions: tabController.index == 1
                    ? [
                        Visibility(
                          visible: controller.conditions.isNotEmpty,
                          child: GestureDetector(
                            onTap: () => controller.addHandler(context),
                            child: Padding(
                              padding:
                                  EdgeInsets.fromLTRB(10.w, 5.h, 20.w, 5.h),
                              child: const Icon(Icons.add),
                            ),
                          ),
                        )
                      ]
                    : null,
              ),
              body: TabBarView(
                physics: const NeverScrollableScrollPhysics(), //禁止滑动
                controller: tabController,
                children: filtes.map((e) => e.permissionWidget).toList(),
              ),
            ),
          );
        });
  }
}
